import java.util.*;
import java.io.* ; 
// 注意类名必须为 Main, 不要有任何 package xxx 信息
//https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66?tpId=122&tqId=33668&ru=/exam/oj
public class MainWY22 {
     static PrintWriter out = new PrintWriter (new BufferedWriter(new OutputStreamWriter(System.out)));
     static Read in = new Read() ;

    public static void main(String[] args)  throws IOException{
       int n = in.nextInt() ;
       if(n ==0 || n==1 || n==2){
        out.println(0);
       }else{
        int cur =2 , prev = 1 ;
        while(cur < n){
            int tmp = cur ;
            cur = cur+prev ;
            prev = tmp ;
        }
        out.println((cur-n)<(n-prev)?(cur-n):(n-prev));


       }

       out.close() ;
    }
}

//class Read{
//    StringTokenizer st = new StringTokenizer("") ;
//
//    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//
//    public String next() throws IOException{
//      while(!st.hasMoreTokens()) {
//        st = new StringTokenizer(bf.readLine());
//      }
//      return st.nextToken() ;
//    }
//    public String nextLine()  throws IOException{
//        return bf.readLine() ;
//    }
//    public int nextInt() throws IOException{
//        return Integer.parseInt(next());
//    }
//    public float nextFloat() throws IOException{
//        return Float.parseFloat(next());
//    }
//
//
//
//}